<?php

namespace App\Models;

/**
 * @mixin IdeHelperProductConfig
 */
class ProductConfig extends BaseModel
{
    // 转售
    public const RESALE_FORBID = 'resale_forbid';
    public const RESALE_DURATION = 'resale_duration';
    public const RESALE_MAX_PRICE = 'resale_max_price';
    public const RESALE_PRICE_INCR_LIMIT = 'resale_price_incr_limit';
    public const RESALE_PRICE_DECR_LIMIT = 'resale_price_decr_limit';
    public const RESALE_INIT_BASE_PRICE = 'resale_init_base_price';
    public const RESALE_BASE_PRICE = 'resale_base_price'; //无需手动配置，自动根据前一天销售数据计算所得

    // 转赠
    public const GIVE_FORBID = 'give_forbid';
    public const GIVE_DURATION = 'give_duration';

    // 锁定
    public const IS_LOCKED = 'is_locked';
    public const EXCHANGE_CHANNEL = 'exchange_channel';

    //其它
    public const SHOW_LEFT_COUNT = 'show_left_count';

    public static function set($contractAddress, $key, $value)
    {
        self::query()->where('contract_address', $contractAddress)
            ->where('config_key', $key)
            ->delete();

        $config = new ProductConfig();
        $config->contract_address = $contractAddress;
        $config->config_key = $key;
        $config->config_value = $value;
        $config->save();
    }
}
